/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	SComplaintConverter.java
 * Created：		2016年8月21日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.complaint.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.SAttachmentConverter;
import com.thor.palmmall.rest.complaint.AComplaint;
import com.thor.palmmall.rest.repair.converter.SWorkOrderConverter;
import com.thor.palmmall.spi.complaint.SComplaint4Create;
import com.thor.palmmall.spi.complaint.SComplaintSource;

/**
 * @author wolv
 *
 */
public class SComplaint4CreateConverter implements Converter<AComplaint, SComplaint4Create> {

  public static SComplaint4CreateConverter getInstance() {
    if (instance == null)
      instance = new SComplaint4CreateConverter();
    return instance;
  }

  private static SComplaint4CreateConverter instance;

  private SComplaint4CreateConverter() {
  }

  @Override
  public SComplaint4Create convert(AComplaint source) {
    if (source == null)
      return null;

    SComplaint4Create target = new SComplaint4Create();
    target.setComplainant(UCN.newInstance(source.getComplainant()));
    target.setComplaintContents(source.getComplaintContents());
    target.setComplaintSource(SComplaintSource.valueOf(source.getComplaintSource().name()));
    target.setContactInfo(source.getContactInfo());
    target.setSourceContract(UCN.newInstance(source.getSourceContract()));
    target.setSourceTenant(UCN.newInstance(source.getSourceTenant()));
    target.setStore(UCN.newInstance(source.getStore()));
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setComplaintObject(source.getComplaintObject());
    target.setAttachmentInfos(
        ConverterUtil.convert(source.getAttachmentInfos(), SAttachmentConverter.getInstance()));
    target.setObjectContract(UCN.newInstance(source.getObjectContract()));
    target.setObjectTenant(UCN.newInstance(source.getObjectTenant()));
    target.setWorkOrder(SWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    target.setType(source.getType());
    return target;
  }
}
